<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/icons-extra.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">	
			<a class="mui-icon mui-icon-back mui-action-back mui-pull-left"></a>
			<h1 class="mui-title ">Barcode</h1>
			<a class="mui-icon-extra mui-icon-extra-topic mui-pull-right" style="margin-top: 10px;"
				 onclick="openWindow('docBarcode','../doc/barcode.html?v=20190621')"></a>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<div class="mui-row">
					Barcode模块管理条码（一维码和二维码）扫描识别，支持常见的一维码（如EAN13码）及二维码（如QR码）。通过调用设备的摄像头对条码进行扫描识别，扫描到条码后进行解码并返回码数据内容及码类型。
				</div>
				<div class="mui-row" style="text-align: center;">
					<img src="../images/barcode.png"/> 
				</div>
				<div class="mui-button-row">
					<button type="button" class="mui-btn mui-btn-success mui-btn-block" onclick="openWindow('barcode_scan.html','barcode_scan.html?v=20190621',true,true);">扫一扫</button>
					<button type="button" class="mui-btn mui-btn-primary mui-btn-block" onclick="openWindow('accelerometer_shake','accelerometer_shake.html?v=20190621')">开始录音</button>
				</div>
				<ul id="history" class="dlist" style="text-align:left;">
					<li id="nohistory" class="ditem" onclick="onempty()">无历史记录	</li>
				</ul>
				<br />
				<div class="mui-row" id="divInfo"></div>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/app.js" ></script>
		<script type="text/javascript">
			mui.init();
			
			function outSet(message){
				document.getElementById("divInfo").innerText = message;
			}
			
			function outLine(message){
				var text = document.getElementById("divInfo").innerText;
				document.getElementById("divInfo").innerText = text + "\n" + message;
			}
			
			var img = null;
			var blist = [];
			function scaned(t, r, f){
				var d = new Date();
				var h=d.getHours(),m=d.getMinutes(),s=d.getSeconds(),ms=d.getMilliseconds();
				if(h < 10){ h='0'+h; }
				if(m < 10){ m='0'+m; }
				if(s < 10){ s='0'+s; }
				if(ms < 10){ ms='00'+ms; }
				else if(ms < 100){ ms='0'+ms; }
				
				var ts = '['+h+':'+m+':'+s+'.'+ms+']';
				var li=null,hl = document.getElementById('history');
				if(blist.length > 0){
					li = document.createElement('li');
					li.className = 'ditem';
					hl.insertBefore(li, hl.childNodes[0]);
				} else{
					li = document.getElementById('nohistory');
				}
				li.id = blist.length;
				var html = '['+h+':'+m+':'+s+'.'+ms+']'+'　　'+t+'码<div class="hdata">';
				html += r;
				html += '</div>';
				li.innerHTML = html;
				li.setAttribute('onclick', 'selected(id)');
				blist[blist.length] = {type:t,result:r,file:f};
				update(t, r, f);
			}
			
			function selected(id){
				var h = blist[id];
				update( h.type, h.result, h.file );
				if(h.result.indexOf('http://')==0  || h.result.indexOf('https://')==0){
					plus.nativeUI.confirm(h.result, function(i){
						if(i.index == 0){
							plus.runtime.openURL(h.result);
						}
					}, '', ['打开', '取消']);
				} else{
					plus.nativeUI.alert(h.result);
				}
			}
			function update(t, r, f){
				outSet('扫描成功：');
				outLine(t);
				outLine(r);
				outLine('\n图片地址：'+f);
				if(!f || f=='null'){
					img.src = '../images/barcode.png';	
				} else{
					plus.io.resolveLocalFileSystemURL(f, function(entry){
						img.src=entry.toLocalURL();
					});
					//img.src = 'http://localhost:13131/'+f;
				}
			}
			function onempty(){
				if(window.plus){
					plus.nativeUI.alert('无扫描记录');
				} else {
					alert('无扫描记录');
				}
			}
			function cleanHistroy(){
				if(blist.length > 0){
					var hl = document.getElementById('history');
					hl.innerHTML = '<li id="nohistory" class="ditem" onclick="onempty();">无历史记录	</li>';
				}
				plus.io.resolveLocalFileSystemURL('_doc/barcode/', function(entry){
					entry.removeRecursively(function(){
						// Success
					}, function(e){
						//alert( "failed"+e.message );
					});
				});
			}
		</script>
	</body>

</html>